package org.elephas.webapp.frontend.component.links;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;
import org.elephas.model.BlogRole;
import org.elephas.webapp.application.ElephasSession;
import org.elephas.webapp.application.security.AuthorizeAction;
import org.elephas.webapp.backend.page.BlogAdminPage;
import org.elephas.webapp.frontend.page.blog.BlogBasePage;
import org.elephas.webapp.frontend.page.blog.BlogFrontPage;

@AuthorizeAction(role = BlogRole.BLOG_ADMIN, action = "RENDER")
public class BlogAdminLinkPanel extends Panel {
    public BlogAdminLinkPanel(String id) {
        super(id);
        add(new Link("admin") {
            @Override
            public void onClick() {
                PageParameters params = new PageParameters();
                params.put(BlogFrontPage.BLOG_NAME, ((BlogBasePage)getPage()).getBlog().getName());
                setResponsePage(new BlogAdminPage(params));
            }
        });
    }

    @Override
    public boolean isVisible() {
        ElephasSession session = ElephasSession.get();
        return session.isSignedIn();
    }

}
